/*
 * @copyright IMTT. Co. Ltd.
 * 
 * Here is detailed comment.
 */
package com.apis.web;


/**
 * @author ZhangMaoren
 * @date 2012-5-25
 * @copyright IMTT. Co. Ltd.
 */
public final class XmlResponse extends Response{
	private static final String RespanseTagBegin = "<response>";
	private static final String RespanseTagEnd = "</response>";
	private static final String RequestTagBegin = "<request>";
	private static final String RequestTagEnd = "</request>";
	private static final String StateTagBegin = "<state>";
	private static final String StateTagEnd = "</state>";
	private static final String MetaDataTagBegin = "<metadata>";
	private static final String MetaDataTagEnd = "</metadata>";
	private static final String DataTagBegin = "<data>";
	private static final String DataTagEnd = "</data>";
	private static final String ReasonTagBegin = "<reason>";
	private static final String ReasonTagEnd = "</reason>";
	private static final String DetailesTagBegin = "<detailes>";
	private static final String DetailesTagEnd = "</detailes>";
	private static final String ExceptionTagBegin = "<excetion>";
	private static final String ExceptionTagEnd = "</excetion>";

	public XmlResponse() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
		sb.append(RespanseTagBegin);

		if (this.request != null) {
			sb.append(RequestTagBegin);
			sb.append("<![CDATA[");
			sb.append(request);
			sb.append("]]>");
			sb.append(RequestTagEnd);
		}

		sb.append(StateTagBegin);
		sb.append(this.state);
		sb.append(StateTagEnd);
		sb.append(DetailesTagBegin);
		
		if (this.metaData != null) {
			sb.append(MetaDataTagBegin);
			sb.append(this.metaData);
			sb.append(MetaDataTagEnd);
		}
		
		if (this.data != null) {
			sb.append(DataTagBegin);
			sb.append(this.data);
			sb.append(DataTagEnd);
		}

		if (this.reason != null) {
			sb.append(ReasonTagBegin);
			sb.append(this.reason);
			sb.append(ReasonTagEnd);
		}
		if (this.exception != null) {
			sb.append(ExceptionTagBegin);
			sb.append("<![CDATA[");
			sb.append(this.exception);
			sb.append("]]>");
			sb.append(ExceptionTagEnd);
		}

		sb.append(DetailesTagEnd);
		sb.append(RespanseTagEnd);
		return sb.toString();
	}

}
